package com.shop.cloud.service.hongfu.impl;

import java.sql.Timestamp;
import java.util.Date;

import com.shop.cloud.domain.hongfu.News;
import com.shop.cloud.service.hongfu.INewsService;
import com.shop.cloud.util.Page;
import com.shop.cloud.dao.hongfu.NewsDao;
import com.shop.cloud.dao.hongfu.TagDao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.shop.cloud.common.mybatis.BaseService;
import com.shop.cloud.common.mybatis.MybatisDao;

/**
 * news
 */
@Service("newsService")
@Transactional
public class NewsService extends BaseService<News> implements INewsService{
    
    @Autowired
	private NewsDao newsDao;
    
    @Autowired
    private TagDao tagDao;
    
    @Autowired
    private NewsService newsService;

	@Override
	public MybatisDao<News> getEntityDao() {
		return newsDao;
	}

	@Override
	public Page<News> pageNews(News news) {
		news.setPageSize((news.getPageSize_()==null?20:news.getPageSize_()));
		long count = newsDao.findNewsCount(news);
		Page<News> page = new Page<News>(news.getPageIndex_(), news.getPageSize_());
		page.setData(newsDao.findNews(news));
		page.setTotalCount(count);
		return page;
	}
	
	@Override
	public Boolean insertNewsAndTag(News news){
		 Date date = new Date();
		 Timestamp datenow = new Timestamp(date.getTime());
	     news.setCreateTime(datenow);
	     Boolean boo = newsService.insert(news);
		      if(boo){
		          		return boo;
		       }
		return false;
	 }
	
	@Override
	public int updateNewsAndTag(News news) {
		Date date = new Date();
		Timestamp datenow = new Timestamp(date.getTime());
		news.setUpdateTime(datenow);
		int row = newsService.update(news);
		if(row>0){
				return 1;
		}
		return 0;
	}

	@Override
	public int deleteNewAndTag(News news) {
	   int row = newsDao.removeByEntity(news);
		if(row>0){

				return 1;

		}
		return 0;
	}
	
	
    
}